package android.com.app;

import java.util.List;

import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;


/* The activity that loads the map */
public class mapviewer extends MapActivity {

	private MapView mv;
	 List<Overlay> mapOverlay;
	 Drawable pin;
	 CustomOverlay pinoverlay;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.apicmapviewer);
		mv = new MapView(this,getResources().getString(R.string.MapAPIKey)); //Add this key in strings.xml
        TextView tv = new TextView(this);
        Bundle extras=getIntent().getExtras();     
        
        // Get the location of this image
		final String[] pos = extras.getString("GeoPoint").split(",");
		tv.setText(pos[0]+","+pos[1]);
		int p1 = (int)(Double.parseDouble(pos[0])*1000000);
		int p2 = (int)(Double.parseDouble(pos[1])*1000000);
		
	  // GeoPoint p = new GeoPoint(19240000,-99120000);  //test location
		
	    GeoPoint p = new GeoPoint(p1,p2);   //passed location
	    Log.i("mapviewer",p1+","+p2);

        MapController mc = mv.getController();
       
        //Set overlays (the red X)
      
       mapOverlay = mv.getOverlays();
       
       pin = this.getResources().getDrawable(android.R.drawable.ic_delete)  ;
       pinoverlay = new CustomOverlay(pin);
       
       OverlayItem overlayitem = new OverlayItem(p, "", "");
       pinoverlay.addOverlay(overlayitem);
       mapOverlay.add(pinoverlay);
       
       mc.animateTo(p);
       mc.setZoom(22);
       mc.setCenter(p);
      //mv.displayZoomControls();
       //mv.setSatellite(true);
       mv.setEnabled(true);
       //mv.computeScroll();

       setContentView(mv);
    }
    
    @Override
    protected boolean isRouteDisplayed() { return false; }
 

	private static final int GAL_ID = Menu.FIRST;
	private static final int CAM_ID = Menu.FIRST+1;
    
    
    @Override
    public boolean onMenuItemSelected(int featureId, MenuItem item) {
        switch(item.getItemId()) {
        case GAL_ID:
        	startActivity(new Intent( this, thumbviewer.class));
            return true;
        case CAM_ID:
        	startActivity(new Intent( this, aPics.class));
        	return true;
        }
        return super.onMenuItemSelected(featureId, item);
    }
    
}
